//
//  SNCompilePlanMoreCell.m
//  ZhuoxinAgriculture
//
//  Created by stone on 16/12/29.
//  Copyright © 2016年 stone. All rights reserved.
//

#import "SNCompilePlanMoreCell.h"
#import "SNCompilePlanOtherButton.h"
#import "SNFertilizerInformationController.h"
#import "SNPesticideInformationController.h"
#import "SNAddPesticideInformationController.h"
#import "SNAddFertilizerInformationController.h"
@interface SNCompilePlanMoreCell()

@property (weak, nonatomic) IBOutlet SNCompilePlanOtherButton *moreButton;

@end
@implementation SNCompilePlanMoreCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (IBAction)moreButtonClicked:(SNCompilePlanOtherButton *)sender {
    NSLog(@"%@ | %s",self.class,__func__);
    switch (self.indexPath.section) {
        case 2:
        {
            @weakify_self
            [self checkWithBlock:^{
                @strongify_self
                SNAddFertilizerInformationController * vc = [SNAddFertilizerInformationController new];
                [self.nav pushViewController:vc animated:YES];
            }];
        }
            break;
        case 3:
        {
            @weakify_self
            [self checkWithBlock:^{
                @strongify_self
                SNAddPesticideInformationController * vc = [SNAddPesticideInformationController new];
                [self.nav pushViewController:vc animated:YES];
            }];
        }
            break;
        default:
            break;
    }
}
- (void)checkWithBlock:(void(^)())block {
    
    if (self.productionPlanListResult.cropTypeName.length > 0) {
        !block ?: block();
    }else{
        [self addAlertViewController];
    }
    
}
- (void)addAlertViewController
{
    NSString * title = @"";
    NSString * message = @"请先编辑概要信息!";
    NSString * actionButtonTitle = @"确定";
    
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction * action = [UIAlertAction actionWithTitle:actionButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // 确定之后需要 处理的code
        
    }];
    
    [alertController addAction:action];
    
    [self.nav presentViewController:alertController animated:YES completion:nil];
}

@end
